package com.xwj.dao;

import com.xwj.domain.UserAccount;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Repository;

import java.math.BigDecimal;

@Repository
@Mapper
public interface UserAccountMapper {
    int deleteByPrimaryKey(Long id);

    int insert(UserAccount record);

    int insertSelective(UserAccount record);

    UserAccount selectByPrimaryKey(Long id);

    int updateByPrimaryKeySelective(UserAccount record);

    int updateByPrimaryKey(UserAccount record);

    UserAccount selectByUserId(Long userId);

    int updateAmount(@Param("money") BigDecimal money, @Param("id") Long id);

    /**
     * 乐观锁：版本号机制
     * @param money
     * @param id
     * @param version
     * @return
     */
    int updateAmountByVersion(@Param("money") BigDecimal money, @Param("id") Long id, @Param("version") Integer version);

    /**
     * 悲观锁：for update查询，行级锁
     * @param userId
     * @return
     */
    UserAccount selectByUserIdLock(Long userId);

    /**
     * 悲观锁
     * @param money
     * @param id
     * @return
     */
    int updateAmountByLock(@Param("money") BigDecimal money, @Param("id") Long id);
}